﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace SmartCity.BasicData.Api.Filters
{
    /// <summary>
    /// 实现了IExceptionFilter 过滤器
    /// </summary>
    public class SCExceptionFilter : IExceptionFilter
    {
        private readonly ILogger<SCExceptionFilter> logger;

        public SCExceptionFilter(ILogger<SCExceptionFilter> logger)
        {
            this.logger = logger;
        }
        /// <summary>
        /// 全局任何一个地方,发生了未处理的异常
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnException(ExceptionContext context)
        {
            logger.LogError("全局异常过滤器捕捉到了一个未处理的异常:"+context.Exception.Message);
            context.ExceptionHandled = true;
        }
    }
}
